﻿ <!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>数据字典</title>
    <link rel="shortcut icon" href="favicon.ico"> 
	<link href="css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="js/plugins/layui/css/layui.css" rel="stylesheet">
    <link href="css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/style.min.css?v=4.0.0" rel="stylesheet">
	<style>
	#layTab_left .showColor{background:#99FFCC;}
	</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-6">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>父级字典</h5>
						<div class="ibox-tools">
							<button id="showAddParentDict" type="button" class="btn btn-sm btn-success add">新增</button>
                            <a class="collapse-link" href="javascript:location.href=location.href;">
                                <i class="fa fa-refresh"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                        <table id="layTab_left" class="table table-striped table-bordered table-hover dataTables-example" >
                            <thead>
                                <tr>
                                    <th>字典名称</th>
                                    <th>代码</th>
                                    <th>创建人</th>
                                    <th>创建时间</th>
									<th>备注</th>
									<th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
							<tfoot>
							
							</tfoot>
                        </table>

                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
						<h5>子级字典</h5>
						<div class="ibox-tools">
							<button id="showAddChildDict" type="button" class="btn btn-sm btn-success add">新增</button>
                            <a class="collapse-link" href="javascript:location.href=location.href;">
                                <i class="fa fa-refresh"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                        
                        <table id="layTab_right" class="table table-striped table-bordered table-hover dataTables-example" >
                            <thead>
                                <tr>
                                    <th>字典名称</th>
                                    <th>代码</th>
                                    <th>创建人</th>
                                    <th>创建时间</th>
									<th>备注</th>
									<th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
							<tfoot>
							
							</tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        
    </div>
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.5"></script>
	<script src="js/plugins/toastr/toastr.min.js"></script>
	<script src="js/plugins/layui/layui.js"></script>
	<script src="js/custom/layTool.js"></script>
    <script type="text/javascript" src="js/custom/app.js" charset="UTF-8"></script>
    <script type="text/javascript" src="js/custom/tools.js" charset="UTF-8"></script>
	
	<script>
	var pageSize = 10;
	var pageNumber = 1;
	var g_dictCode;
	var g_dictName;
	function searchParentDict(pageNumber ,pageSize){
		var url = 'sysDict/getParentDictByPage';
		jQuery.ajax({
			url:domain + url,
			type:"get",
			data:{"page":pageNumber,"pageSize":pageSize},
			crossDomain:true,
			xhrFields:{
				withCredentials:true
			},
			success:function (data) {
				if(data.status == 200){
					var totalPage = data.data.total;//总页数
					pageNumber = data.data.page;//当前页
					var totalRow = data.data.records;//总条数
	   
					//拼凑html
					combHTML(data.data.rows);
				   //分页
					simpleLayPage('layTab_left',totalPage,totalRow,pageNumber ,pageSize,"searchParentDict");
				}else{
					top.toastr.warning(data.msg);
				}
			},
			error:function(data) {
				top.toastr.error("查询列表失败，请检查网络");
			}
		})
		
	}
	
	function combHTML(data){
		var htmls = new Array();
		for (var i=0;i<data.length;i++){
			htmls.push('<tr class="gradeU" data-code="'+ data[i].dictCode + '" data-name="'+data[i].dictName +'">');
			htmls.push('		<td>'+ data[i].dictName +'</td>');
			htmls.push('		<td>'+ data[i].dictCode +'</td>');
			htmls.push('		<td>'+ data[i].createBy +'</td>');
			htmls.push('		<td class="center">'+ data[i].createTime +'</td>');
			htmls.push('		<td>'+ data[i].note +'</td>');
			htmls.push('		<td class="lastTd"><button type="button" data-code="'+ data[i].dictCode 
									+'" class="btn btn-xs btn-outline btn-warning showUpdateParentDict update">修改</button>');
			htmls.push('		<button type="button" data-code="'+ data[i].dictCode 
									+'" class="btn btn-xs btn-outline btn-danger showDeleteParentDict delete">删除</button></td>');
			htmls.push('</tr>');
							
		}
		$("#layTab_left tbody").html(htmls.join(''));
		
		$("#layTab_left tr td:not(.lastTd)").css("cursor","pointer");
		//点击父级字典
		$("#layTab_left tr td:not(.lastTd)").on("click",function(){
			g_dictCode = $(this).parent().data("code");
			g_dictName = $(this).parent().data("name");
			$("#layTab_left tr").removeClass("showColor");
			$(this).parent().addClass("showColor");
			searchChildDict(g_dictCode);
		});
		
		
		//修改父级字典 
		$(".showUpdateParentDict").on("click",function(){
			var dictCode = $(this).data("code");
			layerOpen('修改父级字典','dict-edit-parent.html?dictCode='+encodeURI(dictCode),'400','270')
		});
		
		//删除父级字典
		$(".showDeleteParentDict").on("click",function(){
			var dictCode = $(this).data("code");
			deleteDict(dictCode,"parent");
		});
	}
	
	function searchChildDict(dictCode){
		var url = 'sysDict/getChildDictByPCode';
		jQuery.ajax({
			url:domain + url,
			type:"get",
			data:{"pCode":dictCode},
			crossDomain:true,
			xhrFields:{
				withCredentials:true
			},
			success:function (data) {
				if(data.status == 200){
	   
					//拼凑html
					combChildHTML(data.data);
				}else{
					top.toastr.warning(data.msg);
				}
			},
			error:function(data) {
				top.toastr.error("查询列表失败，请检查网络");
			}
		})
		
	}
	
	function combChildHTML(data){
		var htmls = new Array();
		for (var i=0;i<data.length;i++){
			htmls.push('<tr class="gradeU">');
			htmls.push('		<td>'+ data[i].dictName +'</td>');
			htmls.push('		<td>'+ data[i].dictCode +'</td>');
			htmls.push('		<td>'+ data[i].createBy +'</td>');
			htmls.push('		<td class="center">'+ data[i].createTime +'</td>');
			htmls.push('		<td>'+ data[i].note +'</td>');
			htmls.push('		<td><button type="button" data-code="'+ data[i].dictCode 
									+'" class="btn btn-xs btn-outline btn-warning showUpdateChildDict update">修改</button>');
			htmls.push('		<button type="button" data-code="'+ data[i].dictCode 
									+'" class="btn btn-xs btn-outline btn-danger showDeleteChildDict delete">删除</button></td>');
			htmls.push('</tr>');
							
		}
		$("#layTab_right tbody").html(htmls.join(''));
		
		//修改子级字典 
		$(".showUpdateChildDict").on("click",function(){
			var dictCode = $(this).data("code");
			layerOpen('修改子级字典','dict-edit-child.html?dictCode='+encodeURI(dictCode)+'&pName='+encodeURI(g_dictName),'500','370');
		});
		
		//删除子级字典
		$(".showDeleteChildDict").on("click",function(){
			var dictCode = $(this).data("code");
			deleteDict(dictCode,"child");
		});
	}
	
	
	function deleteDict(dictCode,who){
		layui.use(['layer'], function(){
			var layer = layui.layer;
			layer.confirm('确定删除？', {
				title:false,
				icon:7,
				btn: ["确定",'取消'] //按钮
			}, function(){
				var url = 'sysDict/deleteDictByCode';
				jQuery.ajax({
					url:domain + url,
					type:"post",
					data:{"dictCode":dictCode},
					crossDomain:true,
					xhrFields:{
						withCredentials:true
					},
					success:function (data) {
						if(data.status == 200){
							top.toastr.success("操作成功");
							if(who == "parent"){
								searchParentDict(1,10);
								$("#layTab_right tbody").html('');
							}else{
								searchChildDict(g_dictCode);
							}
							layer.close(layer.index);
						}else{
							top.toastr.warning(data.msg);
						}
					},
					error:function(data) {
						top.toastr.error("查询列表失败，请检查网络");
					}
				})
			});
		});
	}
	
	
	$(function(){
		searchParentDict(pageNumber ,pageSize);
		//新增父级字典 
		$("#showAddParentDict").on("click",function(){
			layerOpen('新增父级字典','dict-add-parent.html','400','280')
		});
		
		
		//新增子级字典 
		$("#showAddChildDict").on("click",function(){
			if(null == g_dictCode || ""==g_dictCode || undefined == g_dictCode){
				top.toastr.warning("请选择父级字典");
				return;
			}
			layerOpen('新增子级字典','dict-add-child.html?pCode='+encodeURI(g_dictCode)+'&pName='+encodeURI(g_dictName),'500','370');
		});
	
	})
	</script>
	
	<script>	//=======   页面权限显示   ======//
	//当前菜单代码 (每个页面不一样，需要配置)
		var s_menuCode = "dictRun";
	//所有可用权限
		var roleAuth = app.permission(s_menuCode);
	//当前菜单所有可用权限（排除被禁用的按钮）
		var menuAuth = app.menuButtonByOn(s_menuCode);
		
		drawBtn(roleAuth,menuAuth);
	</script>
</body>

</html>
